﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdProductOrder.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdProductOrder;
/// <summary>
/// 通过订单编号更新订单服务
/// </summary>
public class UpdateMdProductOrderByIdService : ApiBase<RequestUpdateMdProductOrderByIdModel>
{
    /// <summary>
    /// 订单仓储
    /// </summary>
    public MdProductOrderRep mdProductOrderRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdProductOrderModel();

        model.OrderId = Parameter.OrderId;
        model.ProductId = Parameter.ProductId;
        model.UserId = Parameter.UserId;
        model.AddressId = Parameter.AddressId;
        model.CallbackUrl = Parameter.CallbackUrl;
        model.Reason = Parameter.Reason;
        model.Status = Parameter.Status;
        model.UpdateBy = userKey?.ToString();
        model.UpdateTime = DateTime.Now;
        model.Remark = Parameter.Remark;

        var res = mdProductOrderRep.UpdateMdProductOrderModelById(model);

        if (res > 0)
        {
            Result.Data = mdProductOrderRep.GetMdProductOrderById(model.OrderId);
        }
        else
        {
            Result.Data = res;
        }
    }
}

